package com.oa.entities;

import com.oa.domain.UndeleteEntity;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotEmpty;

import javax.persistence.*;
import javax.validation.constraints.Pattern;
import java.util.ArrayList;
import java.util.List;

@Entity
@Table(name = "oa_role")
public class Role extends UndeleteEntity<Long> {
    /**
     *
     */
    private static final long serialVersionUID = 4923967185427120619L;

    public static final String ROLE_NAME="name";

    private String name;

    /** 描述 */
    private String description;

    /** 权限 */
    private List<String> authorities = new ArrayList<String>();

    /** 创建时间 **/
    private Long createTime;

    @Override
    @Id
    @Column(nullable = false)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    public Long getId() {
        return super.getId();
    }

    @Override
    public void setId(Long id) {
        super.setId(id);
    }

    @NotEmpty
    @Pattern(regexp = "^[0-9a-z_A-Z\\u4e00-\\u9fa5]*$")
    @Length(max = 45)
    @Column(nullable = false, length = 45)
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    /**
     * 获取描述
     *
     * @return 描述
     */
    @Length(max = 200)
    @Column(length = 200)
    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    /**
     * 获取权限
     *
     * @return 权限
     */
    @Column(nullable = false)
    @ElementCollection(fetch = FetchType.LAZY)
    @CollectionTable(name = "oa_role_authority")
    public List<String> getAuthorities() {
        return authorities;
    }

    public void setAuthorities(List<String> authorities) {
        this.authorities = authorities;
    }

    @Column(name = "create_time",nullable = false)
    public Long getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Long createTime) {
        this.createTime = createTime;
    }
}
